{{template "../layout/header.html" .}}
<!-- 内容主体区域 -->
<form class="layui-form" action="add.html" method="post">
<div class="layui-tab layui-tab-card">
    <ul class="layui-tab-title">
        <li class="layui-this">基本设置</li>
        <!--<li>用户管理</li>-->
    </ul>
    <div class="layui-tab-content">

        <div class="layui-form-item">
            <label class="layui-form-label">上级权限</label>
            <div class="layui-input-block">
                <select name="par_path" lay-verify="required">
                    <option value="0">-顶级权限-</option>
                    {{range .Pardata}}
                    <option value="{{.Par_path}}"
                            {{if eq .Par_path $.Data.Par_path}}
                            selected
                            {{end}}
                    >{{.Par_path | ShowCatLevel}}{{.Pri_name}}
                    </option>
                    {{end}}
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">权限名称</label>
            <div class="layui-input-block">
                <input type="text" name="pri_name" required  lay-verify="required" placeholder="请输入权限名称" value="{{.Data.Pri_name}}" autocomplete="off" class="layui-input">
            </div>
        </div>
        <input type="hidden" name="id" value="{{.Data.Id}}" />

        <div class="layui-form-item">
            <label class="layui-form-label">控制器名称</label>
            <div class="layui-input-block">
                <input type="text" name="controller_name" required  lay-verify="required" placeholder="请输入控制器名称" value="{{.Data.Controller_name}}" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">方法名称</label>
            <div class="layui-input-block">
                <input type="text" name="action_name" required  lay-verify="required" placeholder="请输入方法名称" value="{{.Data.Action_name}}" autocomplete="off" class="layui-input">
            </div>
        </div>
                <!--<div class="layui-form-item layui-form-text">-->
                    <!--<label class="layui-form-label">文本域</label>-->
                    <!--<div class="layui-input-block">-->
                        <!--<textarea name="desc" placeholder="请输入内容" class="layui-textarea"></textarea>-->
                    <!--</div>-->
                <!--</div>-->

            </div>
        <!--<div class="layui-tab-item">2</div>-->
    <!--</div>-->
</div>


    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="sub">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>

{{template "../layout/commonjs.html" .}}
<script>
    //Demo
    layui.use(['form','layer','jquery'], function(){
        var form = layui.form;
        var $ = layui.jquery;

        //监听提交
        form.on('submit(sub)', function(data){
            var form_data = $("form").serialize();
            var xsrftoken = $('meta[name=_xsrf]').attr('content');
            $.ajax({
                type: "post",
                url:'{{urlfor "PrivilegeController.Edit"}}',
                dataType: "json",
                data: form_data,
                headers : {'X-Xsrftoken':xsrftoken},
                success: function(out){
                    if (out.status == 0) {
                        layer.msg("操作成功",{icon: 1,time: 500},function () {
                            window.location.href="/privilege/lst"
//                            window.location.reload()
                        })
                    } else {
                        layer.msg(out.message,{icon: 2,time: 500})
                    }
                },
                error: function(out){
                    layer.msg("未知错误",{icon: 2,time: 500})
                }

            });
            return false;
        });
    });
</script>

{{template "../layout/footer.html" .}}